// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class appleAction extends cc.Component {

    onLoad () {
        let random = Math.random();
        if(random > 0.5){
            this.playAnimationAction1();
        }else{
            this.playAnimationAction2();
        }

    }

    playAnimationAction1(){
        cc.tween(this.node).by(0.2,{
            position : cc.v2(0,5),
        }).call(()=>{
            cc.tween(this.node).by(0.2,{
                position : cc.v2(0,-5),
            }).call(()=>{
                this.playAnimationAction1();
            }).start()
        }).start();

        cc.tween(this.node).to(0.1,{
            angle : -5,
        }).call(()=>{
            cc.tween(this.node).to(0.1,{
                angle : 0,
            }).call(()=> {
                cc.tween(this.node).to(0.1, {
                    angle: 5,
                }).call(()=>{
                    cc.tween(this.node).to(0.1, {
                        angle: 0,
                    }).start()
                }).start()
            }).start()
        }).start()
    }

    playAnimationAction2(){
        cc.tween(this.node).by(0.2,{
            position : cc.v2(0,-5),
        }).call(()=>{
            cc.tween(this.node).by(0.2,{
                position : cc.v2(0,5),
            }).call(()=>{
                this.playAnimationAction2();
            }).start()
        }).start();

        cc.tween(this.node).to(0.1,{
            angle : -5,
        }).call(()=>{
            cc.tween(this.node).to(0.1,{
                angle : 0,
            }).call(()=> {
                cc.tween(this.node).to(0.1, {
                    angle: 5,
                }).call(()=>{
                    cc.tween(this.node).to(0.1, {
                        angle: 0,
                    }).start()
                }).start()
            }).start()
        }).start()
    }
}
